Conditions | 2 |
Paths | 1 |
Total Lines | 20 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
Bugs | 0 | Features | 0 |
1 | import { getMetricsInstance } from './init'; |
||
3 | export const createEventMetrics = ({ service, operation, action }) => { |
||
4 | const metrics = getMetricsInstance(); |
||
5 | if (metrics === undefined) { |
||
6 | throw Error(`auto metrics instance needs to be initialised first`); |
||
7 | } |
||
8 | const serviceRoot = `service.${service}.action.${action}`; |
||
9 | const operationRoot = `operation.${operation}.action.${action}`; |
||
10 | const countOne = path => { |
||
11 | metrics.count(`${serviceRoot}.${path}`, 1); |
||
12 | metrics.count(`${operationRoot}.${path}`, 1); |
||
13 | }; |
||
14 | return { |
||
15 | start: () => countOne('state.start'), |
||
16 | success: () => countOne('state.success'), |
||
17 | failure: e => { |
||
18 | countOne(`state.failure.category.${e.category}.status.${e.status}`); |
||
19 | countOne(`state.failure.category.${e.category}.type.${e.type}`); |
||
20 | }, |
||
21 | }; |
||
22 | }; |
||
23 | |||
29 |